package com.bnz.controller.DTO;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author xy
 * @date 2022/10/27
 */
public class UserDto implements UserDetails {
    private String userename;
    private String password;
    private List<String> roleList;

    public void  setUserename(String userename){
        this.userename = userename;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    public void setRoleList(List<String> roleList){
        this.roleList=roleList;
    }
    public List<String> getRoleList(){
        return this.roleList;
    }
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> authorities = new ArrayList<>();
        for (String role:roleList){
            authorities.add(new SimpleGrantedAuthority(role));
        }
        return authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.userename;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
